﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.MicroKernel;
using Castle.MicroKernel.Lifestyle;
using Castle.MicroKernel.Context;

namespace Shape.Mvp.Ioc
{
   public class LeasedLifestyleManager : AbstractLifestyleManager
   {
      private object _leasedObject;

      public override object Resolve(CreationContext context, IReleasePolicy releasePolicy)
      {
         if (_leasedObject == null)
         {
            _leasedObject = base.Resolve(context, releasePolicy);
         }

         return _leasedObject;
      }

      public override void Dispose()
      {
         _leasedObject = null;
      }
   }
}
